<template>
	<view>
		<!-- 选择收获地址的盒子 -->
		<view class="address-choose-box" v-if='!address.userName'>
			<button type="primary" size="mini" @click="getAddress">+请选择收获地址</button>
		</view>

		<!-- 渲染收获信息的盒子 -->
		<view class="address-info-box" v-else @tap='getAddress'>
			<view class="row1">
				<view class="row1-left">
					<view class="username">收货人：<text>{{address.userName}}</text></view>
				</view>
				<view class="row1-right">
					<view class="phone">电话：<text>{{address.telNumber}}</text></view>
					<text class="iconfont icon-fanhui2"></text>
				</view>
			</view>
			<view class="address">
				<view class="row2-left">收获地址：</view>
				<view class="row2-right">{{allAdree}}</view>
			</view>
		</view>
		<!-- 底部的边框线 -->
		<!-- <image src="../../static/cart_border@2x.png" class="address-border"></image> -->
	</view>
</template>

<script>
	export default {
		name: "hjx-address",
		data() {
			return {

			};
		},
		props: ['address'],
		computed: {
			allAdree() {
				let str = this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo;
				return str;
			}
		},
		methods: {
			async getAddress() {
				// 获取收获地址
				const res = await uni.chooseAddress();
				console.log(res)
				// 用户成功的选择了收获地址
				if (res[1].errMsg && res[1].errMsg == 'chooseAddress:ok') {
					uni.setStorageSync('address', res[1])
				}
			}
		},
	}
</script>

<style lang="scss">
	// 底部边框线样式
	.address-border {
		display: block;
		width: 100%;
		height: 5px;
	}

	// 收获地址盒子样式
	.address-choose-box {
		height: 90px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	// 渲染收获信息的盒子样式
	.address-info-box {
		font-size: 14px;
		height: 90px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 5px;

		.row1 {
			display: flex;
			justify-content: space-between;

			.row1-right {
				display: flex;
				justify-content: space-between;
			}
		}

		.address {
			display: flex;
			// justify-content: space-between;
			align-items: center;
			margin-top: 10px;

			.row2-left {
				// 文本不换行
				white-space: nowrap;
			}
		}
	}
</style>
